<template>
  <div class="elmain">
    
    <el-row :gutter="20">
 
      <div>
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/adminHome' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>查看课程</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
      <el-main>
        
        <template>
          <el-table :data="books" @selection-change="changeFun" style="width: 100%">
            <el-table-column type="selection" width="60"></el-table-column>
            <el-table-column prop="courseName" label="待审核课程" width="120"></el-table-column>
            <el-table-column prop="courseTeacher" label="教师" width="120"></el-table-column>
            <el-table-column prop="colloge" label="课程内容" width="120"></el-table-column>
             <el-table-column prop="status" label="审核结果" width="120">待审核</el-table-column>
      
            <el-table-column label="操作">
              <template slot-scope="scope">
                 <el-button size="mini" type="success" @click="del(scope.row.courseid)">通过</el-button>
                <el-button size="mini" type="danger" @click="del(scope.row.courseid)">不通过</el-button>
              </template>
            </el-table-column>
          </el-table>
        </template>
      </el-main>


    </el-row>
  </div>
</template>

<script>
import { getStore } from "../../libs/storage";
export default {
  name: "application",
  data() {
    return {
      // 查询参数
      booksinfo: {
        userid: getStore("userid"),
        bookid: ""
      },
      result: '未通过',
      checkBoxData: [],
      books: [],
      cid: ""
    };
  },
  created() {
    this.listByCategory();
  },
  computed: {
    totalPrice: {
      get() {
        if (this.checkBoxData.length > 0) {
          return this.checkBoxData
            .map(val => parseInt(val.price))
            .reduce((prev, cur) => prev + cur);
        }
      },
      set(newVal) {
        console.log(newVal, "<-->newVal");
      }
    }
  },
  methods: {
    //删除
    async del(id) {
      //询问是否删除
      const confirmResult = await this.$confirm(
        "此操作将创建该课程, 是否继续?",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      ).catch(err => err);

      //确认返回 confirm
      //取消返回 cancel
      if (confirmResult !== 'confirm') {
        return this.$message.info('已取消创建')
      }

      this.$axios
        .post("/success", {
          user: getStore("userid"),
          courseid: id
        })
        .then(resp => {
          if (resp && resp.status === 200) {
            console.log(id);
            this.$message.success("已通过");
            this.listByCategory();
          }
        })
        .catch(failResponse => {
          console.log(id);
          console.log(failResponse.responseResult);
          console.log(getStore("userid"));
        });
    },
    //查询所有
    listByCategory() {
      //alert(1);
      this.$axios
        .post("/aplication", {
          status: '0'
        })
        .then(resp => {
          if (resp && resp.status === 200) {
            this.books = resp.data;
            return;
          }
        })
        .catch(failResponse => {
          console.log(getStore("userid"));
          console.log(failResponse.responseResult);
        });
    },
    //选中的数据
    changeFun(val) {
      this.checkBoxData = val;
      console.log(this.checkBoxData);
    }
  }
};
</script>

<style scoped>
.cover {
  width: 115px;
  height: 172px;
  margin-bottom: 7px;
  overflow: hidden;
  cursor: pointer;
}

img {
  width: 140px;
  height: 175px;
  /*margin: 0 auto;*/
}

.title {
  font-size: 14px;
  text-align: left;
}

.author {
  color: #333;
  width: 102px;
  font-size: 13px;
  margin-bottom: 6px;
  text-align: left;
}

.abstract {
  display: block;
  line-height: 17px;
}

a {
  text-decoration: none;
}

a:link,
a:visited,
a:focus {
  color: #3377aa;
}

.info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: center;
}

.twobutton {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.elmain {
  height: 100%;
}

.el-row {
  height: 100%;
}

.el-main {
  height: 88%;
}

.el-footer {
  margin-bottom: 0px;
  text-align: right;
}

.foottext {
  margin-right: 100px;
}
</style>>